
//调整字符串并比较
//给定两个字符串A和B，A旋转操作，若A旋转n次后和B相同返回true，否则返回false

public class Test {
    public static void main(String[] args) {
        //定义两个字符串
        String strA = "abcde";
        String strB = "cdeab";

        //反转比较
        boolean result = compareStr(strA,strB);
        System.out.println(result);
    }

    //比较
    public static boolean compareStr (String strA,String strB){
        if (strA.length() == strB.length()) {
            for (int i = 0; i < strA.length(); i++) {
                //注意这里需要反转的是上一次反转后获得的，所以直接赋值给原身
                strA = rotate(strA);
//                System.out.println(strA);
                if (strA.equals(strB)) {
                    return true;
                }
            }
        }
        return false;
    }

    //反转
    //采用字符串截取来反转
    public static String rotate(String strA){
        char first = strA.charAt(0);
        String end = strA.substring(1);
        return end + first;
    }

    //将字符串转变为数组进行反转
    public static String rotateChar (String strA){
        char[] crr = strA.toCharArray();
        char first = crr[0];
        for (int i = 1; i < crr.length; i++) {
            crr[i-1] = crr[i];
        }
        crr[crr.length - 1] = first;
        return  new String(crr);
    }
}
